# 视图模块：通过函数，响应
# 导入响应类
from django.http import HttpResponse

def hello_view(request):
    # request 请求对象，固定的参数
    # 创建响应对象，响应一段文本
    html = '<h2>hello world</h2>'
    return HttpResponse(html)

def index_view(request):
    html = '<h1>这是我的首页</h1>'
    return HttpResponse(html)
def page1_view(request):
    html = '<h2>这是编号1为的网站</h2>'
    return HttpResponse(html)
def page2_view(request):
    html = '<h2>这是编号为2的网站</h2>'
    return HttpResponse(html)
def pagen_view(request, pno):
    # 接收任意一个值
    html = f'<h2 style="color:red;">这是编号为{pno}的网站</h2>'
    return HttpResponse(html)

def calc_view(request, n1, op, n2):
    # 判断运算符
    if op == 'add':
        result = n1 + n2
    elif op == 'sub':
        result = n1 - n2
    elif op == 'mul':
        result = n1 * n2
    elif op == 'div':
        result = n1 / n2
    else:
        result = '错误的操作'

    return HttpResponse(f'执行结果：{result}')

def num_view(request, n):
    html = f'<h1>传递的数字：{n}</h1>'
    return HttpResponse(html)
def email_view(request, email):
    html = f'<h1>邮箱：{email}</h1>'
    return HttpResponse(html)



